<?
ob_start(); 
include("common/header.html");
include("common/left.html");
include("common/page.php");
include("class/OrderRecord.php");//查询订单详情和处理订单的相关操作
include("class/ProOrder.php");//票付通平台会员的订单统计，查询操作
include("class/SimpleExcel.class.php");
$out_html=ob_get_contents();
ob_end_clean();
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s= new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID=$_SESSION['sid'];
$str="select id,imgpath from uu_land";//景区id，缩略图
$images=array();
$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
	$images[$row['id']]=$row['imgpath'];
}

$pOrder=buyProOrderObject($memberID,$s,$_SESSION['sdtype']);
$v['title'] ="已买到的产品";
//$v['title2']="分销订单";
$v['from']="buy";
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:15;

$concat=0;

// 导出全部订单
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export"){
	$currentPage=1;
	$pageSize=99999;

}
$r=$pOrder->_orderlist($currentPage,$pageSize,$concat);
if($_REQUEST['method']=='countAll'){
    $countAll = explode(',',$pOrder->totalOrders(2));
    echo json_encode($countAll);
    exit;
}
$orderCount = $ticketCount = $allMoney = 0;// 订单统计信息
//  获取产品对应的供应商列表
if(count($r)){
	$adis = array();
	foreach($r as $key=>$row){
		if(!isset($adis[(string)$row['mainOrder']->UUaid]))
			$adis[(string)$row['mainOrder']->UUaid]=(string)$row['mainOrder']->UUaid;
		// 统计订单信息
		$orderCount++;
		$ticketCount+=(string)$row['mainOrder']->UUtnum;
		// $allMoney+=((int)$row['mainOrder']->UUtotalmoney)/100;
		$allMoney+=((int)$row['mainOrder']->UUtprice*(int)$row['mainOrder']->UUtnum)/100;
	}
	$str="select id,dname from pft_member where dtype=0 AND id IN (".implode(',',$adis).")";
	$anames=array();
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc())
		$anames[$row['id']]=$row['dname'];
}
$tmp = $r;
$arr = array();
foreach($r as $key => $row){
	// 处理
	$concat = (string)$row['mainOrder']->UUconcat_id;
	$orderid = (string)$row['mainOrder']->UUordernum;
	if($concat==0){
		$arr[] = $r[$key];// 主订单
		continue;
	}
	if($concat!=$orderid){
		$tmp[$key]= $r[$key];
		continue;
	}
	// 主订单并且含有从订单
	foreach($tmp as $k=>$data){
		if((string)$data['mainOrder']->UUconcat_id==$orderid && (string)$data['mainOrder']->UUordernum!=$orderid){
			$r[$key]['childOrder'][] = $data;
			unset($tmp[$k]);
		}
	}
	$arr[] = $r[$key];
}
$r = $arr;
// if($_GET['a']){
	// print_r($r);
// }
// 获取对应的供应商
include 'getDistors.php';
$supList = getDistors($GLOBALS['le']);

$dTypeName = '供应商';
$atype= 'buy';// 导出文件名判断条件
include("loadExcel_simple.php");
echo $out_html;
// 判断订单是否为主订单  true为主订单
function isMainOrder($field){
	return ($field=='main' || $field!=0 ) ? true:false;
}
// 复票订单主订单
function echoMainOrder($obj){
	return ((String)$obj->UUconcat_id=='main') ? (String)$obj->UUordernum:(String)$obj->UUconcat_id;
}
$count=$pOrder->orderlistTotal();
$uuStatus = array(0=>"未使用",1=>"<em class='green'>已使用</em>",2=>"已过期",3=>"<em class='red'>已取消</em>",4=>"被替代",5=>"<em class='green'>已使用</em><br/><em class='red'>(被修改)</em>",6=>"已撤销",7=>"部分使用");
// 不显示分销商列
$showDtrArr = array(2223);
$showDtr = true;
if(in_array($_SESSION['sid'], $showDtrArr)){
	$showDtr = false;
}
include("tpl/orderLists_dt.tpl");
include("common/footer.html");

?>